package com.extra_archive.project.iisu.model 
{
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.IOErrorEvent;

	/**
	 * @author implict
	 */
	public class ARModel extends BasicModel 
	{
		private var _configManager : ARConfigManager;
		private var _assetManager : ARAssetManager;
		
		private var _sectionIndex : uint;
		
		public function ARModel($applicationContainer : DisplayObjectContainer)
		{
			super($applicationContainer);	
		}
		
		//--------------------------------------------------------------------------
		//
		//    getter/setter
		//
		//--------------------------------------------------------------------------
		
		public function get configManager() : ARConfigManager
		{
			return _configManager;
		}
		
		public function get assetManager() : ARAssetManager
		{
			return _assetManager;
		}
		
		public function get sectionIndex() : uint
		{
			return _sectionIndex;
		}
		
		public function set sectionIndex(sectionIndex : uint) : void
		{
			_sectionIndex = sectionIndex;
		}

		//--------------------------------------------------------------------------
		//
		//    Public Methods
		//
		//--------------------------------------------------------------------------
		
		override public function initialize() : void 
		{
			createConfigManager();
		}
		
		override public function onGestureConnect(event : Event) : void
		{
			startApplication();
		}
		
		override public function onGestureIOError(event : IOErrorEvent) : void
		{
			startApplication();
		}
		
		override public function toString() : String
		{
			return "com.extra_archive.project.iisu.model.ARModel";
		}
		
		//--------------------------------------------------------------------------
		//
		//    Event Listeners
		//
		//--------------------------------------------------------------------------
		
		private function onLoadConfigComplete(event : BasicModelEvent) : void 
		{
			trace(this + " : onLoadConfigComplete");
			
			createAssetManager();
		}

		private function onLoadAsseetComplete(event : BasicModelEvent) : void 
		{
			trace(this + " : onLoadAsseetComplete");
			
			createGestureModel();
		}
		
		//--------------------------------------------------------------------------
		//
		//    Private Methods
		//
		//--------------------------------------------------------------------------
		
		/**
		 * create config xml data manager
		 * config.xml 로드 및 참조
		 */
		override protected function createConfigManager() : void 
		{
			_configManager = new ARConfigManager("../xml/main.xml");
			_configManager.addEventListener(BasicModelEvent.LOAD_CONFIG_COMPLETE, onLoadConfigComplete);
		}
		
		/**
		 * create asset data manager
		 * config.xml의 asset 이미지 로드 및 참조 
		 */
		override protected function createAssetManager() : void 
		{
			_assetManager = new ARAssetManager(_configManager);
			_assetManager.addEventListener(BasicModelEvent.LOAD_ASSET_COMPLETE, onLoadAsseetComplete);
		}
	}
}
